const Koa = require("koa");
const Router = require("koa-router");
const app = new Koa();
const router = new Router();

router.get("/", (ctx) => {
  console.log(ctx);
  console.log(ctx.request);
  ctx.body = "Hello World";
});

router.get("/api", (ctx) => {
  console.log(ctx);
  console.log(ctx.request);
  ctx.body = "Hello Api";
});

router.get("/cookie", (ctx) => {
  let n = Number(ctx.cookies.get("view") || 0) + 1;
  ctx.cookies.set("view", n);
  ctx.body = n + "Hello cookie";
});

app.use(router.routes()).use(router.allowedMethods());

app.listen(3000);
